var vm = new Vue({
  el : '#app',
  extends: CommonTools,
  
  data : function() {
    return {
      student:{
      },
      teaOptions:{},
      teacher:{},
      attend:{
    	  cause:'',
    	  state:''
      },
      show : false,
      id:'',
      
    }
    
  },
  
  filters: {
    /**
     * 状态名称
     */
    stateName(state) {
      for (var i = 0; i < vm.states.length; ++i) {
        if (vm.states[i].value == state) {
          return vm.states[i].label;
        }
      }
      return state;
    },
    
  },
  
 /* computed: {
  readonly: function(){
      return this.activity && (this.activity.state != 'uncommit');
    },
    
    
  },*/
  
  methods: {
    
    /**
     * 重新加载单据
     */
	  reload(){
	      var self = this;
	      var url = "gStudentController.do?get&id=" 
	        + (this.id?this.id:'');
	      this.get(url).then((data) => {       
	        self.student = data;
	     /*   if(self.student.id != null){
	        	if(self.attend.apResult !="unsubmit"){
	        		self.show = true;
	        	}
	        }*/
	      }).catch(err => {
	        this.showError(err);
	      });
	    },
    
    /**
     * 保存操作
     */
    onSave() {
        var self = this;
        return self.doSave();
      },

    /**
     * 保存
     */
    doSave(){
      var self = this;
      var url = 'gAttendController.do?doAdd1';
      self.attend.stuName=self.student.name;
      self.attend.stuNum=self.student.stuNum;
      self.attend.stuClass=self.student.stuClass;
      self.attend.teaName=JSON.parse(sessionStorage.user).name;
      self.attend.teaNum=JSON.parse(sessionStorage.user).teaNum;
      
        self.post(url, self.attend).then(() => {
          self.showMsg('操作成功！', function() {
           self.goback();
          });
        }).catch(err => {
          self.showError(err);
        });
    },
    
    
    goback(){
      history.back();
    },
    /**
     * 删除请假单单
     */
    onLate(){
      var self = this;
      var url = 'gAttendController.do?doAdd&name='+late;
      this.confirm('确认要提交这个考勤单吗？', function() {
        self.get(url).then(() => {
          self.showMsg('提交成功！', function() {
            self.goback();
          });
        }).catch(err => {
          self.showMsg('提交失败');
        });
      });
    },
    /**
     * 删除请假单单
     */
    onAbsen(){
    	var self = this;
    	var url = 'gattendController.do?doAdd&id=' + self.attend.id;
    	this.confirm('确认要提交这个考勤单吗？', function() {
    		self.get(url).then(() => {
    			self.showMsg('提交成功！', function() {
    				self.goback();
    			});
    		}).catch(err => {
    			self.showMsg('提交失败');
    		});
    	});
    },
    /**
     * 提交请假单单
     */
    onattend(){
    	var self = this;
    	var url = 'gattendController.do?submit&id=' + self.attend.id;
    	this.confirm('确认要提交这个考勤单吗？', function() {
    		self.get(url).then(() => {
    			self.showMsg('提交成功！', function() {
    				self.goback();
    			});
    		}).catch(err => {
    			self.showMsg('提交失败');
    		});
    	});
    },
    
    
  },
  
  created() {
    this.id = this.getQueryParam('id');
    this.reload();
  },
  
});
